<template>
  <div>
    <el-select
      v-if="!disabled"
      :value="value"
      :options="options"
      :clearable="clearable"
      :filterable="filterable"
      :placeholder="placeholder"
      :size="size"
    >
      <el-option
        v-for="item in options"
        :key="item.value"
        :label="item.label"
        :value="item.value"
      />
    </el-select>
    <div v-else>{{ valueStr }}</div>
  </div>
</template>
<script>
export default {
  props: {
    value: [String, Array],
    disabled: {
      type: Boolean,
      default: () => false
    },
    placeholder: {
      type: String,
      default: ''
    },
    clearable: {
      type: Boolean,
      default: false
    },
    size: {
      type: String,
      default: 'small'
    },
    options: {
      type: Array,
      default: () => []
    },
    filterable: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      valueStr: ''
    }
  },
  watch: {
    value: {
      handler(val) {
        if (typeof val === 'object') {
          this.valueStr = val.join('-')
        } else {
          this.valueStr = val
        }
      },
      deep: true,
      immediate: true
    }
  },
  methods: {
    input(e) {
      this.$emit('input', e.target.value)
    }
  }
}
</script>
